import { ReactNode } from 'react';
import styles from './index.module.scss';
import classNames from 'classnames';

interface IInputProps
  // 继承input框的类型属性
  extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
  // 可选的
  className?: string;
  extra?: ReactNode;
  errorMsg?: string;
}

export default function Input(props: IInputProps) {
  const { className, extra, errorMsg, ...restProps } = props;
  return (
    <div className={classNames(styles.root, className)}>
      <div className="input-item">
        <div className="input-box">
          {/* 将剩下的属性关联上去 restProps */}
          <input className="input" {...restProps} />
          <div className="validate">{errorMsg}</div>
          <div className="extra">{extra}</div>
        </div>
      </div>
    </div>
  );
}
